import { Injectable } from '@nestjs/common';
import ZH from './locale/zh'
import EN from './locale/en'

@Injectable()
export class I18nService {
    private locales = {
        ZH,
        EN
    }
    constructor(
    ) {

    }

    t(locale:string, key:string, args?:Array<string|number>) {
        let word:string = key.split('.').reduce((a, b) => a[b], this.locales[locale])
        if(args) {
            args.forEach(arg => {
                word = word.replace('{}', arg as string)
            })
        }

        return word
    }


}
